<?php
namespace app\admin\controller;

use think\Request;
use think\Paginator;
use think\Db;

class Adminmember extends Base
{
    //展示用户信息
    public function member_list()
    {
        $this->view->assign('title', '用户列表');
        $this->view->assign('keywords', '用户列表');
        $this->view->assign('desc', '中小学教育平台');
        //显示用户信息
        $attr = Db::table('User')->paginate(5);
        //显示用户总数
        $count = Db::table('User')->count();
        //渲染到页面
        $this->assign('attr', $attr);
        $this->assign('count', $count);

        return $this->fetch();
    }

    /*
     * 通过该方法把用户身份区分开
     */

    //教师导入
    public function teacher_des()
    {
        $des = Db::table('User')->where(['desting' => 1])->select();
        foreach ($des as $value) {
            $data = [
                'name' => $value['nickname'],
                'mobile' => $value['username'],
                'degree' => 0,
            ];
            $cc = Db::table('teacher')->select();
            foreach ($cc as $valuecc) {
                if ($valuecc['mobile'] == $value['username']) {
                    echo '此用户已存在';
                    exit;
                }

            }
            $loadTeacher = Db::table('teacher')->insertAll($data);
            if ($loadTeacher == true) {
                echo '导入成功';
            }
        }

    }
    //学生导入
    public function student_des()
    {
        /*
         * 查询用户表信息
        */
        $dest = Db::table('User')->where(['desting' => 2])->select();
        foreach ($dest as $value) {
            $data = [
                'name' => $value['nickname'],
                'mobile' => $value['username'],
                'sex' => 0,
            ];
            $dd = Db::table('student')->select();
            foreach ($dd as $valuecc) {
                if ($valuecc['mobile'] == $value['username']) {
                    echo '此用户已存在';
                    exit;
                }

            }
            $loadStudent = Db::table('student')->insert($data);
            if ($loadStudent == true) {
                echo '导入成功';
            }
        }
    }
    //修改用户信息
    public function member_update(Request $request){
        $member_id=$request->param('id');
        var_dump($member_id);die;

    }

    //删除用户信息

    public function member_del(Request $request){
        $member_id=$request->param('id');
        var_dump($member_id);die;
    }


}
